//图片懒加载插件
// 导入视口监听函数
import { useIntersectionObserver } from "@vueuse/core";

export const imglazy = {
  install(app) {
    app.directive("img-lazy", {
      mounted(el, binding) {
        // el指令绑定的元素，binding等号后面的值
        const { stop } = useIntersectionObserver(el, ([{ isIntersecting }]) => {
          if (isIntersecting) {
            el.src = binding.value;
            stop();
          }
        });
      },
    });
  },
};
